package com.example.base.adapter.indicator;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;

import androidx.annotation.RequiresApi;
import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.Utils;
import com.example.base.R;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.List;

public class LineIndicator extends CommonNavigatorAdapter {

    private List<String> tabs;
    private ViewPager viewPager;

    public LineIndicator(ViewPager viewPager, List<String> tabs){
        this.viewPager = viewPager;
        this.tabs = tabs;
    }

    @Override
    public int getCount() {
        return tabs == null ? 0 : tabs.size();
    }

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {
        SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
        simplePagerTitleView.setText(tabs.get(index));
        simplePagerTitleView.setTextSize(16f);
        simplePagerTitleView.setNormalColor(Utils.getApp().getResources().getColor(R.color.app_color_text_regular));
        simplePagerTitleView.setSelectedColor(Utils.getApp().getResources().getColor(R.color.app_color_text_primary));
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager.setCurrentItem(index);
            }
        });
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setColors(Color.TRANSPARENT);
//        indicator.setColors(Utils.getApp().getResources().getColor(R.color.app_color_primary));
        indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        return indicator;
    }
}
